#include "message.hpp"


int main()
{
    //----------------------------------------------rpc请求测试-------------------------------------------------
    // myrpc::RpcRequest::ptr rrp=myrpc::MessageFactory::create<myrpc::RpcRequest>();
    // Json::Value param;
    // param["num1"]=11;
    // param["num2"]=22;
    // rrp->setMethod("Add");
    // rrp->setParams(param);
    // std::string str=rrp->serialize();
    // std::cout<<str<<std::endl;
    // myrpc::BaseMessage::ptr bmp=myrpc::MessageFactory::create(myrpc::MType::REQ_RPC);
    // bool ret=bmp->unserialize(str);
    // if(ret==false)
    // {
    //     return -1;
    // }
    // ret=bmp->check();
    // if(ret==false)
    // {
    //     return false;
    // }
    // myrpc::RpcRequest::ptr rrp2=std::dynamic_pointer_cast<myrpc::RpcRequest>(bmp);
    // std::cout<<rrp->method()<<std::endl;
    // std::cout<<rrp->params()["num1"].asInt()<<std::endl;
    // std::cout<<rrp->params()["num2"].asInt()<<std::endl;


    //----------------------------------------------主题请求测试-------------------------------------------------

    // myrpc::TopicRequest::ptr rrp=myrpc::MessageFactory::create<myrpc::TopicRequest>();
    // rrp->setTopicKey("news");
    // rrp->setTopicOptype(myrpc::TopicOptype::TOPIC_PUBLISH);
    // rrp->setTopicMsg("hello!");
    // std::string str=rrp->serialize();
    // std::cout<<str<<std::endl;

    // myrpc::BaseMessage::ptr bmp=myrpc::MessageFactory::create(myrpc::MType::REQ_TOPIC);
    // bool ret=bmp->unserialize(str);
    // if(ret==false)
    //     return -1;
    
    // ret=bmp->check();
    // if(ret==false)
    //     return -1;

    // myrpc::TopicRequest::ptr rrp2=std::dynamic_pointer_cast<myrpc::TopicRequest>(bmp);
    // std::cout<<(rrp2->topicKey())<<std::endl;
    // std::cout<<((int)rrp2->topicOptype())<<std::endl;
    // std::cout<<(rrp2->topicMsg())<<std::endl;


    //----------------------------------------------服务请求测试-------------------------------------------------
    // myrpc::ServiceRequest::ptr rrp=myrpc::MessageFactory::create<myrpc::ServiceRequest>();
    // rrp->setMethod("Add");
    // rrp->setServiceOptype(myrpc::ServiceOptype::SERVICE_REGISTRY);
    // rrp->setHost(myrpc::Address("127.0.0.1",9090));
    // std::string str=rrp->serialize();
    // std::cout<<str<<std::endl;


    // myrpc::BaseMessage::ptr bmp=myrpc::MessageFactory::create(myrpc::MType::REQ_SERVICE);
    // bool ret=bmp->unserialize(str);
    // if(ret==false)
    //     return -1;
    
    // ret=bmp->check();
    // if(ret==false)
    //     return -1;

    // myrpc::ServiceRequest::ptr rrp2=std::dynamic_pointer_cast<myrpc::ServiceRequest>(bmp);
    // std::cout<<(rrp2->method())<<std::endl;
    // std::cout<<((int)rrp2->serviceOptype())<<std::endl;
    // std::cout<<(rrp2->host().first)<<':'<<rrp2->host().second<<std::endl;

    //----------------------------------------------rpc响应测试-------------------------------------------------

    // myrpc::RpcResponse::ptr rrp=myrpc::MessageFactory::create<myrpc::RpcResponse>();
    // rrp->setRcode(myrpc::RCode::RCODE_OK);
    // rrp->setResult(7);
    // std::string str=rrp->serialize();
    // std::cout<<str<<std::endl;


    // myrpc::BaseMessage::ptr bmp=myrpc::MessageFactory::create(myrpc::MType::RSP_RPC);
    // bool ret=bmp->unserialize(str);
    // if(ret==false)
    //     return -1;
    
    // ret=bmp->check();
    // if(ret==false)
    //     return -1;

    // myrpc::RpcResponse::ptr rrp2=std::dynamic_pointer_cast<myrpc::RpcResponse>(bmp);
    // std::cout<<(int)rrp2->rcode()<<std::endl;
    // std::cout<<rrp2->result()<<std::endl;



    //----------------------------------------------topic响应测试-------------------------------------------------

    // myrpc::TopicResponse::ptr rrp=myrpc::MessageFactory::create<myrpc::TopicResponse>();
    // rrp->setRcode(myrpc::RCode::RCODE_OK);
    // std::string str=rrp->serialize();
    // std::cout<<str<<std::endl;


    // myrpc::BaseMessage::ptr bmp=myrpc::MessageFactory::create(myrpc::MType::RSP_TOPIC);
    // bool ret=bmp->unserialize(str);
    // if(ret==false)
    //     return -1;
    
    // ret=bmp->check();
    // if(ret==false)
    //     return -1;

    // myrpc::TopicResponse::ptr rrp2=std::dynamic_pointer_cast<myrpc::TopicResponse>(bmp);
    // std::cout<<(int)rrp2->rcode()<<std::endl;

    //----------------------------------------------service响应测试-------------------------------------------------

    // myrpc::ServiceResponse::ptr rrp=myrpc::MessageFactory::create<myrpc::ServiceResponse>();
    // rrp->setRcode(myrpc::RCode::RCODE_OK);
    // rrp->setMethod("Add");
    // rrp->setServiceOptype(myrpc::ServiceOptype::SERVICE_DISCOVER);
    // std::vector<myrpc::Address> addrs;
    // addrs.push_back(myrpc::Address("127.0.0.1",9090));
    // addrs.push_back(myrpc::Address("127.0.0.2",9091));
    // rrp->setHost(addrs);

    // std::string str=rrp->serialize();
    // std::cout<<str<<std::endl;


    // myrpc::BaseMessage::ptr bmp=myrpc::MessageFactory::create(myrpc::MType::RSP_SERVICE);
    // bool ret=bmp->unserialize(str);
    // if(ret==false)
    //     return -1;
    
    // ret=bmp->check();
    // if(ret==false)
    //     return -1;
    // myrpc::ServiceResponse::ptr rrp2=std::dynamic_pointer_cast<myrpc::ServiceResponse>(bmp);
    // std::cout<<(int)rrp2->rcode()<<std::endl;
    // std::cout<<(int)rrp2->serviceOptype()<<std::endl;
    // std::cout<<rrp2->method()<<std::endl;
    // std::vector<myrpc::Address> addrs2=rrp2->hosts();
    // for(int i=0;i<addrs2.size();i++)
    // {
    //     std::cout<<addrs2[i].first<<':'<<addrs2[i].second<<std::endl;
    // }
    return 0;
}